//! @author Adam Emil Skoog
//! @date   2012-01-05

#include "House.h"
#include "Game.h"
#include "Mehdi.h"
#include "Block.h"
#include <iostream>

namespace mehdi
 {
	House::House()
	:
	image                (NULL),
	inContactWithMehdi   (false),
	cameraMovementEnabled(false),
	mehdiSpawnPosition   (.0f,.0f)
	 {
		setReceptiveToCollision(false);
		setReceptiveToGravity(false);
	 }

	House &House::setImage(Image *const image)
	 {
		this->image = image;
		return *this;
	 }

	Image *const House::getImage() const
	 {
		return image;
	 }

	House &House::setCameraMovementEnabled(const bool &enable)
	 {
		level->setCameraMovementEnabled((cameraMovementEnabled = enable));
		return *this;
	 }

	const bool &House::cameraMovementIsEnabled() const
	 {
		return cameraMovementEnabled;
	 }

	House &House::setLevel(Level *const level)
	 {
		this->level = level;
	 }

	Level *const House::getLevel() const
	 {
		return level;
	 }

	House &House::setMehdiSpawnPosition(const sf::Vector2f &position)
	 {
		mehdiSpawnPosition = position;
		return *this;
	 }

	const sf::Vector2f &House::getMehdiSpawnPosition() const
	 {
		return mehdiSpawnPosition;
	 }

	void House::draw() const
	 {
		if (getImage())
		 {
			getImage()->SetPosition(position());
			Game::getWindow()->Draw(*image);
		 }
/*
		CollisionMask *const m(getCollisionMasks()[0]);
		Game::getWindow()->Draw(sf::Shape::Rectangle(position().x + m->getPosition().x,position().y + m->getPosition().y,
												     position().x + m->getPosition().x + m->getSize().x,
													 position().y + m->getPosition().y + m->getSize().y,
													 sf::Color(255,0,0,180)));
*/
	 }

	void House::update()
	 {
		if (inContactWithMehdi)
		 {
			if (Mehdi::getCurrentMehdi()->pressedDown())
				Game::enterHouse(level,this);
		 }

		inContactWithMehdi = false;
	 }

	void House::onCollision(Body *const other)
	 {
		if (dynamic_cast<Mehdi *>(other))
			inContactWithMehdi = true;
	 }
 }
